let arr = [
    [1, 0, 0, 2, 0, 4, 0, 0, 0],
    [8, 0, 0, 0, 3, 0, 0, 0, 7],
    [0, 9, 0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 0, 0, 0, 6, 0, 0],
    [3, 0, 8, 0, 7, 6, 0, 0, 0],
    [6, 0, 0, 0, 5, 0, 0, 1, 0],
    [0, 0, 0, 8, 0, 0, 3, 0, 5],
    [0, 0, 4, 0, 0, 5, 0, 0, 0],
    [0, 0, 9, 0, 0, 7, 0, 0, 8]
];


function getGroupNums() {
    let groups = [[2, 3, 5, 7, 8], [2, 3], [2, 4, 5, 9], [2, 4, 5, 9], [2, 4, 9], [2, 4, 7, 8], [2, 3, 4]];

    let numCountMap = {};

    groups.forEach(a => a.forEach(b => {
        numCountMap[b] = numCountMap[b] || 0;
        numCountMap[b]++;
    }));

    let tempGroups = [];

    groups.forEach(a => {
        let item = [];
        let minLength = 999;

        a.forEach(b => {
            minLength = Math.min(minLength, numCountMap[b]);
        });

        a.forEach(b => {
            if (numCountMap[b] === minLength) {
                item.push(b)
            }
        });

        if (item.length === minLength) {
            tempGroups.push(item);
        }
    });

    let arr = tempGroups.map(a => a.join(','));

    let matchMap = {};
    arr.forEach(a => {
        matchMap[a] = matchMap[a] || 0;
        matchMap[a]++;
    });

    let keys = Object.keys(matchMap);
    let resultGroups = [];

    for (let i = 0; i < keys.length; i++) {
        let key = keys[i];
        let keyNums = key.split(',');
        if (matchMap[key] === key.split(',').length) {
            resultGroups.push(keyNums);
        }
    }

    return resultGroups;
}

getGroupNums();